package com.wthink.hzgj.busplan.viewmodel

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.wthink.hzgj.busplan.`interface`.ListCallBack
import com.wthink.hzgj.busplan.data.BusPlan
import com.wthink.hzgj.service.DevService
import com.wthink.hzgj.service.JT808Help
import com.wthink.hzgj.service.jt808.JT_0B07
import com.wthink.hzgj.service.jt808.JT_8B07
import com.wthink.hzgj.util.PreferencesUtils
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch

class BusPlanModel : ViewModel(){

    val busPlanList = MutableLiveData(emptyList<BusPlan>())
    val planDate = MutableLiveData("")

    fun start(){
        JT808Help.setlistCallBack(object : ListCallBack {
            override fun callList(arrayList: ArrayList<BusPlan>,date: String) {
                busPlanList.postValue(arrayList)
                planDate.postValue(date)
            }
        })

    }

    fun reqLine() {

        PreferencesUtils.saveValue("isSelf",true)

        viewModelScope.launch(Dispatchers.IO) {
             DevService.send808(JT_0B07("12345"))
        }
        start()
    }
}